// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   secondKind_delete_ok.java

package hr.config.engage;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class secondKind_delete_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;

	public secondKind_delete_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			PrintWriter out = response.getWriter();
			nseer_db_backup1 hr_db = new nseer_db_backup1(dbApplication);
			if (hr_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String sqll = "select * from hr_config_question_second_kind";
				ResultSet rs = hr_db.executeQuery(sqll);
				rs.next();
				rs.last();
				int intRowCount = rs.getRow();
				String del[] = new String[intRowCount];
				del = (String[])session.getAttribute("del");
				String first_kind_ID[] = new String[intRowCount];
				String first_kind_name[] = new String[intRowCount];
				String second_kind_ID[] = new String[intRowCount];
				String second_kind_name[] = new String[intRowCount];
				String real_del[] = new String[intRowCount];
				int m = 0;
				int n = 0;
				if (del != null)
				{
					for (int i = 1; i <= intRowCount; i++)
						try
						{
							if (del[i - 1] != null)
							{
								real_del[n] = del[i - 1];
								n++;
								String sql2 = (new StringBuilder("select * from hr_config_question_second_kind where id='")).append(del[i - 1]).append("'").toString();
								ResultSet rs2 = hr_db.executeQuery(sql2);
								if (rs2.next())
								{
									first_kind_ID[i - 1] = rs2.getString("first_kind_ID");
									first_kind_name[i - 1] = rs2.getString("first_kind_name");
									second_kind_ID[i - 1] = rs2.getString("second_kind_ID");
									second_kind_name[i - 1] = rs2.getString("second_kind_name");
								}
								String sql3 = (new StringBuilder("select * from hr_questiones where first_kind_ID='")).append(first_kind_ID[i - 1]).append("' and second_kind_ID='").append(second_kind_ID[i - 1]).append("'").toString();
								ResultSet rs3 = hr_db.executeQuery(sql3);
								if (!rs3.next())
								{
									String sql = (new StringBuilder("delete from hr_config_question_second_kind where id='")).append(del[i - 1]).append("'").toString();
									hr_db.executeUpdate(sql);
								} else
								{
									second_kind_ID[m] = second_kind_ID[i - 1];
									second_kind_name[m] = second_kind_name[i - 1];
									m++;
								}
							}
						}
						catch (Exception ex)
						{
							out.println((new StringBuilder("error")).append(ex).toString());
						}

				}
				if (n == 0)
					response.sendRedirect("hr/config/engage/secondKind.jsp");
				else
				if (m < n && m != 0)
				{
					session.setAttribute("second_kind_ID", second_kind_ID);
					session.setAttribute("second_kind_name", second_kind_name);
					session.setAttribute("second_kind_count", (new StringBuilder(String.valueOf(m))).toString());
					response.sendRedirect("hr/config/engage/secondKind_delete_ok_c.jsp");
				} else
				if (m == n)
					response.sendRedirect("hr/config/engage/secondKind_delete_ok_a.jsp");
				else
				if (m == 0)
					response.sendRedirect("hr/config/engage/secondKind_delete_ok_b.jsp");
				hr_db.commit();
				hr_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception exception) { }
	}
}
